home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / src / ConfigFileSrc.lha / ConfigFileSrc12 / Library / Funcs / Find.c < prev    next >
Encoding:
Text File  |  1997-10-02  |  4.2 KB  |  181 lines

  1. /*
  2. **        $PROJECT: ConfigFile.library
  3. **        $FILE: Find.c
  4. **        $DESCRIPTION: cf_Find#?() functions
  5. **
  6. **        (C) Copyright 1996-1997 Marcel Karas
  7. **             All Rights Reserved.
  8. */
  9.  
  10. IMPORT struct Library    * UtilityBase;
  11.  
  12. /****** configfile.library/cf_FindArgument ***********************************
  13. *
  14. *   NAME
  15. *        cf_FindArgument -- Finds a specfic argument node. (case sensitive)
  16. *
  17. *   SYNOPSIS
  18. *        ArgNode = cf_FindArgument(GrpNode,Name);
  19. *        D0                        A0     A1
  20. *
  21. *        CFArgument * cf_FindArgument(CFGroup *,STRPTR);
  22. *
  23. *   FUNCTION
  24. *        This function finds a specfic argument node.
  25. *
  26. *   INPUTS
  27. *        GrpNode - The group node of the argument list to search.
  28. *        Name - Name of the argument node. 
  29. *
  30. *   RESULT
  31. *        ArgNode - The argument node or NULL.
  32. *
  33. *   SEE ALSO
  34. *        cf_FindGroup(), cf_FindItem()
  35. *
  36. ******************************************************************************
  37. *
  38. */
  39.  
  40. LibCall iCFArgument * cf_FindArgument ( REGA0 iCFGroup * GrpNode , REGA1 STRPTR Name )
  41. {
  42.     iCFArgument * ArgNode;
  43.  
  44.     FuncDe(bug("cf_FindArgument($%08lx,\"%ls\")\n{\n", GrpNode, Name));
  45.  
  46.     if ( ArgNode = cf_LockArgList (GrpNode) )
  47.     {
  48.         while ( ArgNode = cf_NextArgument (ArgNode) )
  49. //            if ( !Stricmp (Name, ArgNode->Name) ) return (ArgNode);
  50.             if ( !StrCmp (Name, ArgNode->Name) )
  51.             {
  52.                 FuncDe(bug("   return($%08lx)\n}\n", ArgNode));
  53.                 return (ArgNode);
  54.             }
  55.         
  56.         cf_UnlockArgList (GrpNode);
  57.     }
  58.  
  59.     FuncDe(bug("   return(NULL)\n}\n"));
  60.     return (NULL);
  61. }
  62.  
  63. /****** configfile.library/cf_FindGroup **************************************
  64. *
  65. *   NAME
  66. *        cf_FindGroup -- Finds a specfic group node. (case sensitive)
  67. *
  68. *   SYNOPSIS
  69. *        GrpNode = cf_FindGroup(Header,Name);
  70. *        D0                     A0     A1
  71. *
  72. *        CFGroup * cf_FindGroup(CFHeader *,STRPTR);
  73. *
  74. *   FUNCTION
  75. *        This function finds a specfic group node.
  76. *
  77. *   INPUTS
  78. *        Header - A pointer to the Header of the group list to search.
  79. *        Name - Name of the group node.
  80. *
  81. *   RESULT
  82. *        GrpNode - The group node or NULL.
  83. *
  84. *   SEE ALSO
  85. *        cf_FindArgument(), cf_FindItem()
  86. *
  87. ******************************************************************************
  88. *
  89. */
  90.  
  91. LibCall iCFGroup * cf_FindGroup ( REGA0 iCFHeader * Header , REGA1 STRPTR Name )
  92. {
  93.     iCFGroup * GrpNode;
  94.  
  95.     FuncDe(bug("cf_FindGroup($%08lx,\"%ls\")\n{\n", Header, Name));
  96.  
  97.     if ( GrpNode = cf_LockGrpList (Header) )
  98.     {
  99.         while ( GrpNode = cf_NextGroup (GrpNode) )
  100.             if ( !StrCmp (Name, GrpNode->Name) )
  101.             {
  102.                 FuncDe(bug("   return($%08lx)\n}\n", GrpNode));
  103.                 return (GrpNode);
  104.             }
  105. //            if ( !Stricmp (Name, GrpNode->Name) ) return (GrpNode);
  106.  
  107.         cf_UnlockGrpList (Header);
  108.     }
  109.  
  110.     FuncDe(bug("   return(NULL)\n}\n"));
  111.     return (NULL);
  112. }
  113.  
  114. /****** configfile.library/cf_FindItem ***************************************
  115. *
  116. *   NAME
  117. *        cf_FindItem -- Finds a specfic item node.
  118. *
  119. *   SYNOPSIS
  120. *        ItemNode = cf_FindItem(ArgNode,Contents,Type);
  121. *        D0                     A0      D0       D1
  122. *
  123. *        CFItem * cf_FindItem(CFArgument *,LONG,ULONG);
  124. *
  125. *   FUNCTION
  126. *        This function finds a specfic item node.
  127. *
  128. *   INPUTS
  129. *        ArgNode - The argument node of the item list to search.
  130. *        Contents - Contents of the item node.
  131. *        Type - The type of contents (if NULL the function fails).
  132. *
  133. *   RESULT
  134. *        ItemNode - The item node or NULL.
  135. *
  136. *   SEE ALSO
  137. *        cf_FindArgument(), cf_FindGroup()
  138. *
  139. ******************************************************************************
  140. *
  141. */
  142.  
  143. SLibCall iCFItem * cf_FindItem ( REGA0 iCFArgument * ArgNode , REGD0 LONG Contents , REGD1 ULONG Type )
  144. {
  145.     iCFItem * ItemNode;
  146.  
  147.     FuncDe(bug("cf_FindItem($%08lx,[$%08lx,%ld],%ld)\n{\n", ArgNode,
  148.         Contents, Contents, Type));
  149.  
  150.     if ( ItemNode = cf_LockItemList (ArgNode) )
  151.     {
  152.         while ( ItemNode = cf_NextItem (ItemNode) )
  153.         {
  154.             if ( ItemNode->Type == Type )
  155.             {
  156.                 if ( Type == CF_ITYP_STRING )
  157.                 {
  158.                     if ( !StrCmp ((STRPTR)Contents, ItemNode->Contents.String) )
  159.                     {
  160.                         FuncDe(bug("   return($%08lx)\n}\n", ItemNode));
  161.                         return (ItemNode);
  162.                     }
  163.                 }
  164.                 else
  165.                 {
  166.                     if ( ItemNode->Contents.Number == Contents )
  167.                     {
  168.                         FuncDe(bug("   return($%08lx)\n}\n", ItemNode));
  169.                         return (ItemNode);
  170.                     }
  171.                 }
  172.             }
  173.         }
  174.  
  175.         cf_UnlockItemList (ArgNode);
  176.     }
  177.  
  178.     FuncDe(bug("   return(NULL)\n}\n"));
  179.     return (NULL);
  180. }
  181.